import {base, high, promptBox} from 'nc-lightapp-front';
import setButtonStatus from "./setButtonStatus";
import initCardForm from "./initCardForm";
import handleAllpks from "./handleAllpks";
import checkPsnInfo from "./checkPsnInfo";
// 初始化处理template数据
export default function processTemplate(template, btnConf = []) {
    const _that = this;
    /*template['blacklist'].items.map((item, index) => {
        item.width = '120px';
    });*/
    let editConf = btnConf.find(btn => btn.key === 'edit');
    let delConf = btnConf.find(btn => btn.key === 'delete');
    let checkConf = btnConf.find(btn => btn.key === 'check');
    template['blacklist'].items.push({
        itemtype: 'customer',
        width: '120px',
        label: this.state.json['hi6007-000029'], /* 国际化处理： 操作*/
        visible: true,
        fixed: 'right',
        attrcode: 'opr',
        render: (text, record, index) => {
            return (
                <div>
                    {
                        (editConf && (_that.state.orgVal.refpk == null || record.values.pk_org.value === _that.state.orgVal.refpk))
                        &&
                        <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            style={{marginRight: '20px'}}
                            onClick={() => {
                                this.setState({
                                    // 为了和选中的数据对应上
                                    pk_psndoc_bad: record.values.pk_psndoc_bad.value,
                                    pk_psndoc: record.values.pk_psndoc.value
                                }, () => {
                                    checkPsnInfo.call(this, this.state, () => {
                                        this.setState({
                                            page: 'edit'
                                        }, () => {
                                            this.headerNode.setPrePage('main');
                                            setButtonStatus.call(this, 'edit');
                                            initCardForm.call(this);
                                        });
                                    })
                                });
                            }}
                        >
                            {editConf['title']}
                        </a>
                    }
                    {
                        (delConf && (_that.state.orgVal.refpk == null || record.values.pk_org.value === _that.state.orgVal.refpk)) &&
                        record.values.delflag.value === true &&
                        <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={() => {
                                this.setState({
                                    // 为了和选中的数据对应上
                                    pk_psndoc_bad: record.values.pk_psndoc_bad.value,
                                    pk_psndoc: record.values.pk_psndoc.value
                                }, () => {
                                    checkPsnInfo.call(this, this.state, () => {
                                        this.setState({
                                            deleteConfirmModalVisible: true
                                        });
                                    })
                                });
                            }}
                        >
                            {delConf['title']}
                        </a>
                    }
                    {
                        (checkConf && (_that.state.orgVal.refpk == null || record.values.pk_org.value === _that.state.orgVal.refpk)) &&
                        record.values.delflag.value === false &&
                        <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={
                                () => {
                                    _that.setState({
                                        // 为了和选中的数据对应上
                                        pk_psndoc_bad: record.values.pk_psndoc_bad.value,
                                        pk_psndoc: record.values.pk_psndoc.value
                                    }, () => {
                                        checkPsnInfo.call(this, this.state, () => {
                                            promptBox(
                                                {
                                                    color: "warning",
                                                    title: this.state.json['hi6007-000008'], /* 国际化处理： 提示*/
                                                    content: this.state.json['hi6007-000010'], /* 国际化处理： 解除后数据将不可恢复,要继续吗？*/
                                                    beSureBtnClick: function () {

                                                        _that.setState({
                                                            checkModalVisible: true
                                                        });
                                                    }
                                                })
                                        })
                                    });
                                }
                            }
                        >
                            {checkConf['title']}
                        </a>
                    }
                </div>
            );
        }
    });

    return template
}
